package com.future.config;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Description:
 *
 * @author weiruibai.vendor
 * Date: 2022/10/10 15:21
 */
@Configuration
public class ZkConfig {

    private static final Logger LOGGER = LoggerFactory.getLogger(ZkConfig.class);

    @Autowired
    WrapperZk wrapperZk;

    @Bean(initMethod = "start")
    public CuratorFramework curatorFramework() {
        RetryPolicy retrYPolicy = new ExponentialBackoffRetry(wrapperZk.getBaseSleepTimeMs(), wrapperZk.getRetryCount());
        CuratorFramework client = CuratorFrameworkFactory.newClient(wrapperZk.getConnectString(), retrYPolicy);
        LOGGER.info("zk curator初始化完成...");
        return client;
    }
}
